<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-collapse *ngIf="resourceData?.sub_type !== dataMap.Resource_Type.msVirtualMachine.value"
    [lvMultiExpansion]="'false'" lvType="simple">
    <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form [formGroup]='formGroup' class="formGroup" [lvLabelColon]='false'>
            <lv-form-item *ngIf="showProxyHost">
                <lv-form-label>
                    {{'protection_clients_label' | i18n}}
                    <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_proxy_host_help_label' | i18n}}"
                        lvTooltipPosition="rightTop"  class="configform-constraint"
                        lvColorState='true'></i>
                </lv-form-label>
                <lv-form-control>
                    <lv-select lvShowClear [lvOptions]='proxyHost' formControlName='proxyHost' lvValueKey='key'
                        lvMode="multiple" lvShowFilter lvShowCheckAll lvFilterKey="label" lvFilterMode="contains"
                        [lvContentTemplate]="contentTpl"
                        lvPlaceholder="{{'protection_agent_placeholder_label' | i18n}}">
                    </lv-select>
                    <ng-template #contentTpl let-item>
                        <lv-group lvGutter="4px">
                            <i lv-icon="{{
                              item.link_status === dataMap.resource_LinkStatus.normal.value ? 'aui-host-online' : 'aui-host-offline'
                            }}"></i>
                            <span
                                [ngClass]="{'host-warp': isSingleHostClusterProtect && item.extendInfo?.is_belongs_to_host_or_cluster === 'true'}"
                                lv-overflow>
                                {{ item.label }}
                            </span>
                            <ng-container
                                *ngIf="isSingleHostClusterProtect && item.extendInfo?.is_belongs_to_host_or_cluster === 'true'">
                                <lv-tag [(ngModel)]="belongTag" [ngModelOptions]="{standalone: true}"
                                    lvMaxWidth="420"></lv-tag>
                            </ng-container>
                        </lv-group>
                    </ng-template>
                </lv-form-control>
            </lv-form-item>
            <!-- 修改索引设置 -->
            <aui-update-index [formGroup]="formGroup" [extParams]="extParams"
                [noNeedMgt]="!isVirtualMachine || resourceType===dataMap.Resource_Type.vmGroup.value"></aui-update-index>
            <lv-form-item *ngIf="false">
                <lv-form-label>
                    {{'protection_protect_pre_script_label' | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]='baseUtilService.scriptNameErrorTip'>
                    <input lv-input type='text' formControlName='preScript'
                        placeholder="{{'common_script_linux_window_placeholder_label'|i18n}}" />
                </lv-form-control>
            </lv-form-item>
            <lv-form-item *ngIf="false">
                <lv-form-label>
                    {{'protection_protect_post_script_label' | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]='baseUtilService.scriptNameErrorTip'>
                    <input lv-input type='text' formControlName='postScript'
                        placeholder="{{'common_script_linux_window_placeholder_label'|i18n}}" />
                </lv-form-control>
            </lv-form-item>
            <ng-container *ngIf="!isVirtualMachine || resourceType===dataMap.Resource_Type.vmGroup.value">
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_concurrent_number_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]='concurrentErrorTip'>
                        <input lv-input type='text' formControlName='concurrent' placeholder="1~99999999" />
                    </lv-form-control>
                </lv-form-item>
                <!-- 虚拟机组按规则过滤需要覆盖策略 -->
                <lv-form-item *ngIf="!isVirtualMachine || isGroupRule">
                    <lv-form-label>
                        {{'protection_overwrite_policy_label' | i18n}}
                        <i lv-icon="aui-icon-help" [lv-tooltip]="slaOverwriteHelp" lvTooltipPosition="rightTop"
                             class="configform-constraint" lvColorState='true'></i>
                    </lv-form-label>
                    <lv-form-control>
                        <lv-radio-group formControlName="slaOverwrite">
                            <lv-group [lvGutter]="'8px'" lvDirection='vertical' class="mgt-8">
                                <lv-radio [lvValue]="true" [lvDisabled]="resourceData.ext_parameters">
                                    {{'protection_overwrite_sla_label' | i18n}}
                                </lv-radio>
                                <lv-radio [lvValue]="false" [lvDisabled]="resourceData.ext_parameters">
                                    {{'protection_not_overwrite_sla_label' | i18n}}
                                    <i lv-icon="aui-icon-help" *ngIf="!isGroupRule"
                                        lv-tooltip="{{'protection_not_overwrite_modify_sla_label' | i18n:[selectedTitle]}}"
                                         style="vertical-align: sub;" lvColorState='true'></i>
                                </lv-radio>
                            </lv-group>
                        </lv-radio-group>
                    </lv-form-control>
                </lv-form-item>
                <ng-container *ngIf="!isVirtualMachine">
                    <lv-form-item>
                        <lv-form-label>
                            {{'protection_apply_policy_label' | i18n}}
                        </lv-form-label>
                        <lv-form-control>
                            <lv-checkbox-group formControlName="slaPolicy" [lvDisabled]="disabled">
                                <lv-group [lvGutter]="'8px'" lvDirection='vertical' class="mgt-8">
                                    <lv-checkbox lvValue="APPLY_TO_ALL">
                                        {{'protection_apply_sla_in_host_label' | i18n:[selectedTitle] }}
                                        <i lv-icon="aui-icon-help" [lv-tooltip]="slaApplyAllHelp"
                                            lvTooltipPosition="rightTop"  lvColorState='true'></i>
                                    </lv-checkbox>
                                    <lv-checkbox lvValue="APPLY_TO_NEW">
                                        {{'protection_apply_sla_in_new_vm_label' | i18n:[selectedTitle]}}
                                    </lv-checkbox>
                                </lv-group>
                            </lv-checkbox-group>
                        </lv-form-control>
                    </lv-form-item>
                    <aui-protect-filter [formGroup]="formGroup" [valid$]="valid$" [resType]="resourceType">
                    </aui-protect-filter>
                </ng-container>
            </ng-container>
        </lv-form>
        <!-- 防勒索副本设置参数 -->
        <ng-container>
            <aui-copy-limit-advanced-parameter [formGroup]="formGroup"
                [data]="resourceData"></aui-copy-limit-advanced-parameter>
        </ng-container>
    </lv-collapse-panel>
</lv-collapse>

<ng-template #titleTpl>
    <span class="aui-h3">{{'common_advanced_label'|i18n}}</span>
</ng-template>
